<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/7
 * Time: 9:48
 */

namespace app\admin\controller;
use think\Request;
use \think\Db;
use app\common\model\Dog as DogModel;
use app\common\model\Area as AreaModel;
use app\common\model\DogFamily as DogFamilyModel;

class Mutual extends \app\admin\controller\Base
{
    protected $res = array(
        'index'   => array('css' => '2,3,4', 'js' => 'list,My97DatePicker'),
//        'statistics'   => array('css' => '2,3,4', 'js' => 'echart,My97DatePicker'),
        'column'   => array('css' => '2,3,4', 'js' => 'echart,My97DatePicker'),
        'style'   => array('css' => '2,3,4', 'js' => 'echart,My97DatePicker'),
    );
    public function index(){
        $DogModel = new DogModel();
        $AreaModel = new AreaModel();
        $search = input('get.search/a');
        $page = input('get.page');
        $search = $this->search($search, $page);
        $list = $DogModel->mutualDog(15,$search);
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $wherePro['level'] = 1;
        if($search[1]!=''){
            $whereCity['pid'] = $search[1];
        }else{
            $whereCity['pid'] = 2;
        }
        if($search[2]!=''){
            $whereDistrict['pid'] = $search[2];
        }else{
            $whereDistrict['pid'] = 52;
        }
        $province =$AreaModel->selectArea($wherePro);
        $city =$AreaModel->selectArea($whereCity);
        $district =$AreaModel->selectArea($whereDistrict);
        $this->assign(
            array(
                'action'=>$action,
                'list'=>$list,
                'page'=>$page,
                'search' => $search,
                'province' => $province,
                'city' => $city,
                'district' => $district,
                'dog_help_status'=>$DogModel::$dog_help_status,
                'user_attestation'=>$DogModel::$user_attestation,
                'udf_condition'=>$DogModel::$udf_condition
            )
        );
        return $this->fetch();
    }
    /**
     * @return  $info      查询到的数据
     * 互助详细信息
     */
    public function details(){
        $dog_id = input('param.dog_id');
        $res = Db::table('up_dog')
            ->where('dog_id', $dog_id)
            ->field('dog_type, dog_information, udf_id')
            ->find();
        if($res['dog_type'] != 2){
            return $this->api_dbError('不能查看其他类型狗的详情');
        }
        $info = Db::table('up_dog_family')
            ->where('udf_id', $res['udf_id'])
            ->field('udf_sex, udf_size, udf_age, udf_character, udf_character_other, 
            udf_dog_vaccine, udf_dog_outside, udf_dog_inside, udf_dog_sterilization, udf_dog_disability')
            ->find();
        $where['uco_id'] = array('IN', $info['udf_character']);
        $character = Db::table('up_dog_character')->where($where)->column('uco_character');
        //狗的性格
        if($character){
            if($info['udf_character_other']){
                $info['udf_character'] = implode(',', $character).','.$info['udf_character_other'];
            }else{
                $info['udf_character'] = rtrim(implode(',', $character), ',');
            }
        }else{
            $info['udf_character'] = '';
        }
        //狗的性别
        if($info['udf_sex'] == 1){
            $info['udf_sex'] = '公';
        }else{
            $info['udf_sex'] = '母';
        }
        //狗的体形
        if($info['udf_size'] == 1){
            $info['udf_size'] = '小型犬';
        }else if($info['udf_size'] == 2){
            $info['udf_size'] = '中型犬';
        }else{
            $info['udf_size'] = '大型犬';
        }
        //狗的年龄
        switch ($info['udf_age']){
            case 1:
                $info['udf_age'] = '不满 12 个月';
                break;
            case 2:
                $info['udf_age'] = '1-3 岁';
                break;
            case 3:
                $info['udf_age'] = '4-6 岁';
                break;
            case 4:
                $info['udf_age'] = '7 岁以上';
                break;
            default:
                $info['udf_age'] = '不详';
        }
        //是否注射狂犬育苗
        if($info['udf_dog_vaccine'] == 1){
            $info['udf_dog_vaccine'] = '否';
        }else if($info['udf_dog_vaccine'] == 2){
            $info['udf_dog_vaccine'] = '是';
        }else{
            $info['udf_dog_vaccine'] = '不详';
        }
        //是否体外驱虫
        if($info['udf_dog_outside'] == 1){
            $info['udf_dog_outside'] = '否';
        }else if($info['udf_dog_outside'] == 2){
            $info['udf_dog_outside'] = '是';
        }else{
            $info['udf_dog_outside'] = '不详';
        }
        //是否体内驱虫
        if($info['udf_dog_inside'] == 1){
            $info['udf_dog_inside'] = '否';
        }else if($info['udf_dog_inside'] == 2){
            $info['udf_dog_inside'] = '是';
        }else{
            $info['udf_dog_inside'] = '不详';
        }
        //是否绝育
        if($info['udf_dog_sterilization'] == 1){
            $info['udf_dog_sterilization'] = '否';
        }else if($info['udf_dog_sterilization'] == 2){
            $info['udf_dog_sterilization'] = '是';
        }else{
            $info['udf_dog_sterilization'] = '不详';
        }
        //是否残疾
        if($info['udf_dog_disability'] == 1){
            $info['udf_dog_disability'] = '否';
        }else if($info['udf_dog_disability'] == 2){
            $info['udf_dog_disability'] = '是';
        }else{
            $info['udf_dog_disability'] = '不详';
        }
        //互助说明
        $info['dog_information'] = $res['dog_information'];
        $this->assign('info', $info);
        return $this->fetch();
    }
    /**
     * 导出excel
     * @return $data  需要导出的数据
     */
    public function excelDownload(){
        $DogModel = new DogModel();
        $search = input('post.search/a');
        $res = $DogModel->excelData($search, 2, 'dog_help_status');
        $result = array();
        foreach ($res as $key=>$vo){
            //需要互助狗的ID
            $result[$key]['dog_id'] = $vo['dog_id'];
            //狗的状态
            if($vo['dog_help_status'] == 1){
                $result[$key]['dog_help_status'] = '待帮助';
            }else if($vo['dog_help_status'] == 2){
                $result[$key]['dog_help_status'] = '已解决';
            }else if($vo['dog_help_status'] == 3){
                $result[$key]['dog_help_status'] = '暂停帮助';
            }else{
                $result[$key]['dog_help_status'] = '已过期';
            }
            //发现城市   省.市.区
            $result[$key]['province'] = $vo['province'].$vo['city'].$vo['district'];
            //发布时间
            $dog_time = strtotime($vo['dog_release_time']);
            $result[$key]['dog_time'] = date('Y', $dog_time).'/'.date('m', $dog_time).'/'.date('d', $dog_time).'  '.date('H', $dog_time).':'.date('i', $dog_time);
            //互助截止时间
            if($vo['dog_end_time'] != ''){
                $result[$key]['dog_end_time'] = date('Y-m-d', strtotime($vo['dog_end_time']));
            }else{
                $result[$key]['dog_end_time']='';
            }
            //互助类别
            $result[$key]['dog_help_style'] = $vo['dog_help_style'];
            //互助说明
            $result[$key]['dog_information'] = $vo['dog_information'];
            //需要互助狗的状况
            if($vo['udf_condition']==1){
                $result[$key]['udf_condition'] = '待救助流浪狗';
            }else if($vo['udf_condition']==2){
                $result[$key]['udf_condition'] = '已救助流浪狗';
            }else if($vo['udf_condition']==3){
                $result[$key]['udf_condition'] = '家养宠物';
            }else if($vo['udf_condition']==4){
                $result[$key]['udf_condition'] = '不详';
            }else{
                $result[$key]['udf_condition'] = '';
            }
            //狗的性别
            if($vo['udf_sex'] == 1){
                $result[$key]['udf_sex'] = '公';
            }else if($vo['udf_sex'] == 2){
                $result[$key]['udf_sex'] = '母';
            }else{
                $result[$key]['udf_sex'] = '';
            }
            //狗的年龄阶段
            switch ($vo['udf_age']){
                case 1:
                    $result[$key]['udf_age'] = '不满 12 个月';
                    break;
                case 2:
                    $result[$key]['udf_age'] = '1-3 岁';
                    break;
                case 3:
                    $result[$key]['udf_age'] = '4-6 岁';
                    break;
                case 4:
                    $result[$key]['udf_age'] = '7 岁以上';
                    break;
                default:
                    $result[$key]['udf_age'] = '不详';
            }
            //狗的体形
            if($vo['udf_size'] == 1){
                $result[$key]['udf_size'] = '小型犬';
            }else if($vo['udf_size'] == 2){
                $result[$key]['udf_size'] = '中型犬';
            }else if($vo['udf_size'] == 3){
                $result[$key]['udf_size'] = '大型犬';
            }else{
                $result[$key]['udf_size'] = '';
            }
            //狂犬育苗
            if($vo['udf_dog_vaccine'] == 1){
                $result[$key]['udf_dog_vaccine'] = '否';
            }else if($vo['udf_dog_vaccine'] == 2){
                $result[$key]['udf_dog_vaccine'] = '是';
            }else if($vo['udf_dog_vaccine'] == 3){
                $result[$key]['udf_dog_vaccine'] = '不详';
            }else{
                $result[$key]['udf_dog_vaccine'] = '';
            }
            //体内驱虫
            if($vo['udf_dog_inside'] == 1){
                $result[$key]['udf_dog_inside'] = '否';
            }else if($vo['udf_dog_inside'] == 2){
                $result[$key]['udf_dog_inside'] = '是';
            }else if($vo['udf_dog_inside'] == 3){
                $result[$key]['udf_dog_inside'] = '不详';
            }else{
                $result[$key]['udf_dog_inside'] = '';
            }
            //体外驱虫
            if($vo['udf_dog_outside'] == 1){
                $result[$key]['udf_dog_outside'] = '否';
            }else if($vo['udf_dog_outside'] == 2){
                $result[$key]['udf_dog_outside'] = '是';
            }else if($vo['udf_dog_outside'] == 3){
                $result[$key]['udf_dog_outside'] = '不详';
            }else{
                $result[$key]['udf_dog_outside'] = '';
            }
            //是否绝育
            if($vo['udf_dog_sterilization'] == 1){
                $result[$key]['udf_dog_sterilization'] = '否';
            }else if($vo['udf_dog_sterilization'] == 2){
                $result[$key]['udf_dog_sterilization'] = '是';
            }else if($vo['udf_dog_sterilization'] == 3){
                $result[$key]['udf_dog_sterilization'] = '不详';
            }else{
                $result[$key]['udf_dog_sterilization'] = '';
            }
            //是否残疾
            if($vo['udf_dog_disability'] == 1){
                $result[$key]['udf_dog_disability'] = '否';
            }else if($vo['udf_dog_disability'] == 2){
                $result[$key]['udf_dog_disability'] = '是';
            }else if($vo['udf_dog_disability'] == 3){
                $result[$key]['udf_dog_disability'] = '不详';
            }else{
                $result[$key]['udf_dog_disability'] = '';
            }
            //狗的性格
            $result[$key]['udf_character'] = $vo['udf_character'];
            //用户ID
            $result[$key]['user_id'] = $vo['user_id'];
            //狗主人的认证状态
            if($vo['user_attestation'] == 2 || $vo['user_attestation'] == 3){
                $result[$key]['user_attestation'] = '是';
            }else{
                $result[$key]['user_attestation'] = '否';
            }
            //狗主人的性别
            if($vo['user_gender'] == 1){
                $result[$key]['user_sex'] = '男';

            }else{
                $result[$key]['user_sex'] = '女';

            }
            //主人年龄
            if($vo['user_card'] != ''){
                $result[$key]['user_age'] = $this->getAgeByID($vo['user_card']);
                $result[$key]['address'] = $this->userCard(substr($vo['user_card'],0,2));
            }else{
                $result[$key]['user_age'] = '';
                $result[$key]['address'] ='';
            }
            //设备
            if($vo['equipment']!=''){
                $result[$key]['equipment'] =$vo['equipment'];
            }else{
                $result[$key]['equipment'] ='';
            }
            //留言数量
            $result[$key]['total'] = $vo['total'];
        }
        $xlsCell  = array(
            array('dog_id','需要互助狗的ID'),
            array('dog_help_status','需要互助狗的状态'),
            array('province','城市'),
            array('dog_time', '发布时间'),
            array('dog_end_time','互助截止时间'),
            array('dog_help_style','互助类别'),
            array('dog_information', '互助说明'),
            array('udf_condition', '需要互助狗的状况'),
            array('udf_sex', '需要互助狗的性别'),
            array('udf_age', '需要互助狗的年龄阶段'),
            array('udf_size', '需要互助狗的体形'),
            array('udf_dog_vaccine', '是否注射狂犬育苗'),
            array('udf_dog_inside', '是否体内驱虫'),
            array('udf_dog_outside', '是否体外驱虫'),
            array('udf_dog_sterilization', '是否绝育'),
            array('udf_dog_disability', '是否残疾'),
            array('udf_character', '需要互助狗的性格'),
            array('user_id', '用户ID'),
            array('user_attestation','是否认证'),
            array('user_sex','主人性别'),
            array('user_age','主人年龄'),
            array('address','户口所在地'),
            array('equipment','设备'),
            array('total', '留言数量')
        );
        $data = $this->exportExcel($xlsCell,$result);
        return $data;
    }
    /**
     *  互助数量情况  柱状图显示
     *  @return    mixed
     */
    public function column(){
        $DogModel = new DogModel();
        $AreaModel = new AreaModel();
        $search = input('get.search/a');
        $page = input('get.page');
        $search = $this->search($search, $page);
        $list = $DogModel->mutualDog(15,$search);
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $wherePro['level'] = 1;
        if($search[1]!=''){
            $whereCity['pid'] = $search[1];
        }else{
            $whereCity['pid'] = 2;
        }
        if($search[2]!=''){
            $whereDistrict['pid'] = $search[2];
        }else{
            $whereDistrict['pid'] = 52;
        }
        $province =$AreaModel->selectArea($wherePro);
        $city =$AreaModel->selectArea($whereCity);
        $district =$AreaModel->selectArea($whereDistrict);
        $this->assign(
            array(
                'action'=>$action,
                'page'=>$page,
                'search' => $search,
                'province' => $province,
                'city' => $city,
                'district' => $district,
            )
        );
        return $this->fetch();
    }
    /**
     *  @return \think\response\Json
     *  互助数量状况  柱状图数据
     */
    public function echartsColumn(){
        $DogFamilyModel = new DogFamilyModel();
        $search = input('param.search/a');

        if($search[3]!=''&&$search[4]!=''){
            $date_time = $this->prDates($search[3],$search[4],$search[5]);
        }else{
            $date_time = $this->prDates();
        }

        $result = array();
        foreach ($date_time as $key => $vo){
            $result['time'][]=$vo;
            if($search[5]==1){
                $whereHe['u.dog_time'] = array('elt',$vo);
            }else if($search[5]==2){
                $whereHe['u.dog_month'] = array('elt',$vo);
            }else if($search[5]==3){
                $whereHe['u.dog_year'] = array('elt',$vo);
            }else{
                $whereHe['u.dog_time'] = array('elt',$vo);
            }
            if($search[5]==1){
                $whereHe1['u.dog_time'] = array('EQ',$vo);
            }else if($search[5]==2){
                $whereHe1['u.dog_month'] = array('EQ',$vo);
            }else if($search[5]==3){
                $whereHe1['u.dog_year'] = array('EQ',$vo);
            }else{
                $whereHe1['u.dog_time'] = array('EQ',$vo);
            }
            $value  = $this->getArray($search, $whereHe, 2);
            $value1  = $this->getArray($search,$whereHe1, 2);
            $result['value'][]=$value?$value:0;
            $result['value1'][]=$value1?$value1:0;
        }
        $totalNum = $this->getNum($search);//获取所有需要互助的狗的数量
        $wNum = $this->getNum($search, 1);//获取待帮助的需要互助的狗的数量
        $yNum = $this->getNum($search, 2);//获取已解决的需要互助的狗的数量
        $sNum = $this->getNum($search, 3);//获取暂停互助的狗的数量
        $pNum = $this->getNum($search, 4);//获取已过期的需要互助的狗的数量
        $rNum = $DogFamilyModel->countNum(1);//获取所有登记狗的数量
        if($rNum != 0){
            $tNumP = number_format($totalNum/$rNum, 2)*100;//需要互助的狗与登记的狗的占比
        }else{
            $tNumP = 0;
        }
        if($totalNum != 0){
            $wNumP = number_format($wNum/$totalNum, 2)*100;//所有待帮助的需要互助的狗的占比
            $yNumP = number_format($yNum/$totalNum, 2)*100;//所有已解决的需要互助的狗的占比
            $sNumP = number_format($sNum/$totalNum, 2)*100;//所有已解决的需要互助的狗的占比
            $pNumP = number_format($pNum/$totalNum, 2)*100;//所有已过期的需要互助的狗的占比
        }else{
            $wNumP = 0;
            $yNumP = 0;
            $pNumP = 0;
            $sNumP = 0;
        }
        $data = array(
            'result' =>   $result,
            'wNum'   =>   $wNum,
            'wNumP'  =>   $wNumP,
            'yNum'   =>   $yNum,
            'yNumP'  =>   $yNumP,
            'sNum'   =>   $sNum,
            'sNumP'  =>   $sNumP,
            'pNum'   =>   $pNum,
            'pNumP'  =>   $pNumP,
            'tNumP'  =>   $tNumP
        );
        return json($data);
    }
    /**
     *  @return \think\response\Json
     *  互助类别统计  显示
     */
    public function style(){
        $DogModel = new DogModel();
        $AreaModel = new AreaModel();
        $DogFamilyModel = new DogFamilyModel();
        $search = input('get.search/a');
        $page = input('get.page');
        $search = $this->search($search, $page);
        $list = $DogModel->mutualDog(15,$search);
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $wherePro['level'] = 1;
        if($search[1]!=''){
            $whereCity['pid'] = $search[1];
        }else{
            $whereCity['pid'] = 2;
        }
        if($search[2]!=''){
            $whereDistrict['pid'] = $search[2];
        }else{
            $whereDistrict['pid'] = 52;
        }
        $province =$AreaModel->selectArea($wherePro);
        $city =$AreaModel->selectArea($whereCity);
        $district =$AreaModel->selectArea($whereDistrict);
        $this->assign(
            array(
                'action'=>$action,
                'page'=>$page,
                'search' => $search,
                'province' => $province,
                'city' => $city,
                'district' => $district,
                'dog_help_status' => $DogModel::$dog_help_status,
                'udf_condition' =>$DogFamilyModel::$udf_condition
            )
        );
        return $this->fetch();
    }
    /**
     *  @return \think\response\Json
     *  互助类别柱状图统计
     */
    public function stylePie(){
        $search = input('param.search/a');
        if($search[3] != '' && $search[4] != ''){
            $date_time = $this->prDates($search[3], $search[4], $search[5]);
        }else{
            $date_time = $this->prDates();
        }
//        $count = count($date_time);
//        if($search[5]==''){//默认年月日
//            $start = $date_time[0];
//            $end = $date_time[count($date_time)-1];
//            $whereMap['u.dog_time'] = array('between',array($start,$end));
//        }else{//证明按了点击按钮
//            $whereMap = $this->dateArray($search,$count,$date_time);
//        }

        $result = array();
        foreach ($date_time as $key => $vo){
            $result['time'][]=$vo;
            if($search[5]==1){
                $whereHe['u.dog_time'] = array('EQ',$vo);
            }else if($search[5]==2){
                $whereHe['u.dog_month'] = array('EQ',$vo);
            }else if($search[5]==3){
                $whereHe['u.dog_year'] = array('EQ',$vo);
            }else{
                $whereHe['u.dog_time'] = array('EQ',$vo);
            }
            if($search[0]!=''){
                $where['u.area_sheng'] = array('=',$search[0]);
            }
            if($search[1]!=''){
                $where['u.area_shi'] = array('=',$search[1]);
            }
            if($search[2]!=''){
                $where['u.area_qu'] = array('=',$search[2]);
            }
            if($search[6] != ''){
                $where['u.dog_help_status'] = array('=', $search[6]);
            }
            if($search[7] != ''){
                $where['udf.udf_condition'] = array('=', $search[7]);
            }
            $where['u.dog_type'] = 2;
            $heoInfo = Db::table('up_dog_heo')->select();
            $otherInfo = array('heo_id' => 0, 'heo_name' => '其它');
            array_push($heoInfo, $otherInfo);
            $total = '';
            foreach($heoInfo as $keys => &$val) {
                $heo_id = ',' . $val['heo_id'] . ',';
                $styleNum = Db::table('up_dog')
                    ->alias('u')
                    ->join('up_dog_family udf', 'udf.udf_id = u.udf_id', 'left')
                    ->where('dog_help_style', 'like', "%$heo_id%")
                    ->where($where)
                    ->where($whereHe)
                    ->count();
                $res[$val['heo_id']]=$styleNum?$styleNum:0;
                $total =   $total+$styleNum;
            }

            foreach($res as $k => $v){
                if($total != 0){
                    $res[$k] = number_format($v/$total, 2)*100;
                }else{
                    $res[$k] = 0;
                }
            }
            $data[]=$res;
        }
        $aa = array('normal'=>array('show'=>true,'formatter'=>'{c}%','position'=>'top'));//'normal:{show:true}';
        foreach ($heoInfo as $key=>$vo){
            $a = array_column($data,$vo['heo_id']);
            $resData[$key]['data'] = $a;
            $resData[$key]['name'] = $vo['heo_name'];
            $resData[$key]['type'] = 'bar';
            $resData[$key]['label'] = $aa;
        }
        $data = array(
            'data1'=>$resData,
            'time'=>$result['time'],
            'name'=>$heoInfo
        );
        return json($data);
    }
    /**
     * @param  $search    查询条件
     * @param  $status    互助的状态
     * @return $num     统计出的数量
     */
    public function getNum($search, $status=''){
        $where = $this->getWhere($search);
        $where['dog_type'] = 2;
        if($status != ''){
            $where['dog_help_status'] = $status;
        }
        //时间条件
        if($search[3] != '' && $search[4] != ''){
            $date_time = $this->prDates($search[3], $search[4], $search[5]);
        }else{
            $date_time = $this->prDates();
        }
        $count = count($date_time);
        if($search[5] == ''){//默认年月日
            $start = $date_time[0];
            $end = $date_time[$count-1];
            $whereMap['u.dog_time'] = array('between',array($start,$end));
        }else{//证明按了点击按钮
            $whereMap = $this->dateArray($search,$count,$date_time);
        }
        $num = Db::table('up_dog')->alias('u')->where($where)->where($whereMap)->count();
        return $num;
    }
    /**
     * @param   $search   查询条件
     * @return  $list     返回的数组
     * 查询互助狗的记录数
     */
    public function getMutualNum($search){
        $where = $this->getWhere($search);
        $where['dog_type'] = 2;
        //时间条件
        if($search[3] != '' && $search[4] != ''){
            $date_time = $this->prDates($search[3], $search[4], $search[5]);
        }else{
            $date_time = $this->prDates();
        }
        $count = count($date_time);
        if($search[5] == ''){//默认年月日
            $start = $date_time[0];
            $end = $date_time[$count-1];
            $whereMap['u.dog_time'] = array('between',array($start,$end));
        }else{//证明按了点击按钮
            $whereMap = $this->dateArray($search,$count,$date_time);
        }
        $num = Db::table('up_dog')->alias('u')
            ->where($where)
            ->where($whereMap)
            ->count();
        return $num;
    }
    /**
     *  搜索条件  互助数量柱状图
     * @param  $search   搜索条件
     * @retern $where    返回的数组
     */
    public function getWhere($search){
        $where = array();
        if($search[0]!=''){
            $where['u.area_sheng'] = array('=',$search[0]);
        }
        if($search[1]!=''){
            $where['u.area_shi'] = array('=',$search[1]);
        }
        if($search[2]!=''){
            $where['u.area_qu'] = array('=',$search[2]);
        }
        return $where;
    }
    /**
     *  搜索条件  互助类别柱状图
     * @param  $search   搜索条件
     * @retern $where    返回的数组
     */
    public function getStyleArray($search, $whereMap){
        $where = array();
        if($search[0]!=''){
            $where['u.area_sheng'] = array('=',$search[0]);
        }
        if($search[1]!=''){
            $where['u.area_shi'] = array('=',$search[1]);
        }
        if($search[2]!=''){
            $where['u.area_qu'] = array('=',$search[2]);
        }
        if($search[6] != ''){
            $where['u.dog_help_status'] = array('=', $search[6]);
        }
        if($search[7] != ''){
            $where['udf.udf_condition'] = array('=', $search[7]);
        }
        $where['u.dog_type'] = 2;
        $heoInfo=array();
        $heoInfo = Db::table('up_dog_heo')->select();
        $otherInfo = array('heo_id' => 0, 'heo_name' => '其它');
        array_push($heoInfo, $otherInfo);
        foreach($heoInfo as $key => &$val) {
            $heo_id = ',' . $val['heo_id'] . ',';
            $styleArray = Db::table('up_dog')
                ->alias('u')
                ->join('up_dog_family udf', 'udf.udf_id = u.udf_id', 'left')
                ->where('dog_help_style', 'like', "%$heo_id%")
                ->where($where)
                ->where($whereMap)
                ->count();
        }

        return $styleArray;
    }



    /**
     * @param $search
     * @param $whereS
     * @param $type
     * @return int|string
     * 查询柱状图和折线图需要的数据  f 互助数量
     */
    public function getArray($search, $whereMap, $type){
        $where = '';
        if($search[0]!=''){
            $where['u.area_sheng'] = array('=',$search[0]);
        }
        if($search[1]!=''){
            $where['u.area_shi'] = array('=',$search[1]);
        }
        if($search[2]!=''){
            $where['u.area_qu'] = array('=',$search[2]);
        }
        $where['u.dog_type'] = $type;
        $branch = Db::table('up_dog')->alias('u')
            ->where($where)
            ->where($whereMap)
            ->count();
        //总的数据
        return $branch;
    }

    /**
     * 查询市
     */
    public function city($city){
//        $city = $_POST['city'];
        $cityArray = Db::table('up_area')->where('pid',$city)->select();
        $data['cityArray'] = $cityArray;
        return json($data);
    }
    /**
     * 查询区
     */
    public function area($area){
//        $area = $_POST['area'];
        $cityArray = Db::table('up_area')->where('pid',$area)->select();
        $data['cityArray'] = $cityArray;
        return json($data);
    }

    /***
     * @return \think\response\Json
     * 删除
     */
    public function delDog(){
        $ids = strtoarray(input('post.ids'));
        $DogFamilyModel = new DogModel();
        $where['dog_id'] = array('In', $ids);
        $result = $DogFamilyModel->where($where)->delete();
        if ($result) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_dbError();
        }
    }
}